package com.xique.door.bean.validation;

import com.xique.common.core.utils.DateUtils;
import com.xique.common.core.utils.MathUtil;
import com.xique.common.core.utils.StringUtils;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.door.bean.domain.BuildHouse;
import com.xique.door.bean.domain.BuildHouseUser;
import com.xique.door.bean.domain.User;
import com.xique.door.service.IBuildHouseService;
import com.xique.door.service.IBuildHouseUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @description:
 * @author caogq
 * @date: 2022/3/26 14:43
 * @Param
 */
@Component
public class HouseUserValidation {
    @Autowired
    private IBuildHouseService buildHouseService;

    @Autowired
    private IBuildHouseUserService buildHouseUserService;

    public AjaxResult userBandHouseValidation(BuildHouseUser buildHouseUser){
        //判断业主是否已存在
        BuildHouseUser search = new BuildHouseUser();
        search.setHouseId(buildHouseUser.getHouseId());
        if ("0".equals(buildHouseUser.getIdentityType())){
            search.setIdentityType(buildHouseUser.getIdentityType());
            List<BuildHouseUser> buildHouseUsers = buildHouseUserService.selectBuildHouseUserList(search);

            if (!buildHouseUsers.isEmpty()) {
                return AjaxResult.error("业主已存在！");
            }
        }

        return AjaxResult.success();
    }
}
